<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <title>第三方API接口收集文档</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="description" content="第三方API接口收集文档" />
    <!-- 禁止搜索引擎索引 -->
    <meta name="robots" content="noindex, nofollow" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
    <!-- 默认主题 -->
    <link id="theme-style" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/docsify/4.13.1/themes/vue.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/plugins/line-numbers/prism-line-numbers.min.css"  />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/plugins/line-highlight/prism-line-highlight.min.css" />
    <style>
    /* 自定义样式：确保主题切换按钮与 navbar 在同一行 */
    .app-nav {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .theme-switcher {
        cursor: pointer;
        font-size: 16px;
        text-decoration: none;
        border-radius: 4px;
        transition: all 0.3s ease;
        margin: 0 1rem;
    }

    .theme-switcher:hover {
        opacity: 0.8;
        /* 悬停时透明度变化 */
    }

    .markdown-section pre>code {
        padding: 10px;
    }

    .markdown-section pre[data-lang] {
        overflow: auto !important;
    }

    .markdown-section pre[data-lang] code {
        overflow: visible;
    }

    .line-numbers .line-numbers-rows {
        border-right: 0px solid white;
        /* Fix paddings to align with code.*/
        padding: 5px;
        /* Same as code block */
    }
    </style>
</head>

<body>
    <div id="app"></div>
    <script>
    // 动态生成时间戳
    const timestamp = new Date().getTime();
    const themeLink = document.getElementById("theme-style");

    // 加载用户上次选择的主题
    let currentTheme = localStorage.getItem("docsify-theme") || "vue"; // 默认主题为 vue
    // themeLink.href = `https://cdnjs.cloudflare.com/ajax/libs/docsify/4.13.1/themes/${currentTheme}.min.css?timestamp=${timestamp}`;

    themeLink.href = `https://cdnjs.cloudflare.com/ajax/libs/docsify/4.13.1/themes/${currentTheme}.min.css`;

    // Docsify 配置
    window.$docsify = {
        name: "第三方API接口收集文档", // 文档站点名称
        loadSidebar: true, // 启用侧边栏
        loadNavbar: true, // 启用导航栏
        autoHeader: true, // 自动生成标题
        subMaxLevel: 6, // 自动生成标题链接的最大层级
        search: "auto", // 启用搜索功能
        auto2top: true, // 启用自动滚动到顶部
        mergeNavbar: true, // 合并导航栏
        externalLinkTarget: "_blank", // 外部链接打开方式
        search: {
            maxAge: 86400000, // 缓存时间（毫秒）
            paths: "auto", // 搜索范围
            placeholder: "Type to Search", // 搜索框占位符
            noData: "No Results!",
        },
        copyCode: {
            buttonText: 'Copy',
            errorText: 'Error',
            successText: 'Copied',
        },

        markdown: {
            renderer: {
                code: function(code, lang) {
                    // return this.origin.code.apply(this, arguments);
                    if (lang == 'html') {
                        code = code.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
                    }

                    return ('<pre data-lang="' + lang + '"><code class="line-numbers language-' + lang + '">' + code + '</code></pre>')
                }
            }
        },

        // 启用 lastUpdated 插件
        // lastUpdated: true, // 显示文档更新时间
        //  formatUpdated: "{YYYY}-{MM}-{DD} {HH}:{mm}:{ss}", // 时间格式化
        // 自定义插件：添加主题切换功能
        plugins: [
            function(hook, vm) {
                hook.init(function() {
                    // 监听路由变化
                    // 使用原生路由监听方式
                    window.addEventListener("hashchange", function() {
                        setTimeout(addThemeSwitcher, 10);
                    });
                });
                hook.doneEach(function(html) {
                    // 确保主题切换按钮只添加一次
                    addThemeSwitcher();
		         Prism.highlightAll();	
                });

                hook.mounted(function() {
                    // 页面首次加载时添加主题切换按钮
                    addThemeSwitcher();
                });
            },
        ],
    };

    // 添加主题切换按钮
    function addThemeSwitcher() {
        const checkNavbar = () => {
            const navbar = document.querySelector(".app-nav");
            if (navbar) {
                const existingSwitcher = navbar.querySelector(".theme-switcher");
                if (!existingSwitcher) {
                    const switcher = document.createElement("div");
                    switcher.className = "theme-switcher";
                    switcher.textContent = "切换主题";
                    switcher.onclick = toggleTheme;
                    navbar.appendChild(switcher);
                    updateThemeSwitcherColor(); // 同步颜色
                }
            } else {
                // 如果导航栏未加载，延迟重试
                setTimeout(checkNavbar, 10);
                console.log("导航栏未加载,导航容器未生成，请检查配置");
            }
        };
        checkNavbar();
    }

    // 主题切换逻辑
    const themes = ["vue", "dark"]; // 可选主题列表

    function toggleTheme() {
        const nextTheme =
            themes[(themes.indexOf(currentTheme) + 1) % themes.length];
        currentTheme = nextTheme;

        // 更新主题样式
        // themeLink.href = `https://cdnjs.cloudflare.com/ajax/libs/docsify/4.13.1/themes/${nextTheme}.min.css?timestamp=${timestamp}`;
        themeLink.href = `https://cdnjs.cloudflare.com/ajax/libs/docsify/4.13.1/themes/${nextTheme}.min.css`;

        // 保存用户选择的主题
        localStorage.setItem("docsify-theme", nextTheme);

        // 更新按钮文字颜色
        updateThemeSwitcherColor();
    }

    // 更新按钮文字颜色以匹配当前主题
    function updateThemeSwitcherColor() {
        const switcher = document.querySelector(".theme-switcher");
        if (switcher) {
            // 根据当前主题设置文字颜色
            switch (currentTheme) {
                case "vue":
                    switcher.style.color = "#34495e"; // 默认主题文字颜色
                    break;
                case "dark":
                    switcher.style.color = "#c8c8c8"; // 深色主题文字颜色
                    break;
                default:
                    switcher.style.color = "#34495e"; // 默认回退颜色
            }
        }
    }

    // 页面加载完成后初始化按钮颜色
    document.addEventListener("DOMContentLoaded", function() {
        updateThemeSwitcherColor();
    });

  
   </script>
    <!-- Docsify v4 -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/docsify/4.13.1/docsify.min.js"></script>
    <!-- 引入 Docsify 搜索插件 -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/docsify/4.13.1/plugins/search.min.js"></script>
    <!-- 引入 Docsify 复制到剪切板插件 -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/docsify-copy-code/3.0.0/docsify-copy-code.min.js"></script>
    <!-- 引入时间更新插件 -->
    <script src="./assets/time-updater.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/11.10.1//mermaid.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/components/prism-bash.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/components/prism-css.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/components/prism-javascript.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/components/prism-php.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/components/prism-java.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/components/prism-scss.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/plugins/line-numbers/prism-line-numbers.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/plugins/line-highlight/prism-line-highlight.min.js"></script>

    
</body>

</html>
<script>
if (typeof navigator.serviceWorker !== "undefined") {
    navigator.serviceWorker.register("sw.js");
    console.log("register serviceWorker successed!");
}
</script>
